package com.c6906.vdam.dcs.protocol.t808;

import com.c6906.vdam.common.model.APICodes;
import com.c6906.vdam.common.model.APIException;
import com.c6906.vdam.dcs.protocol.basics.JTMessage;
import com.c6906.vdam.dcs.protocol.commons.JT808;
import io.github.yezhihao.protostar.annotation.Field;
import io.github.yezhihao.protostar.annotation.Message;
import io.swagger.v3.oas.annotations.media.Schema;
import org.bouncycastle.util.encoders.Hex;

import java.nio.charset.StandardCharsets;


/**
 * @author com.6906
 */
@Message({JT808.平台RSA公钥, JT808.终端RSA公钥})
public class T0A00_8A00 extends JTMessage {

    @Field(length = 4, desc = "RSA公钥{e,n}中的e")
    private int e;
    @Field(length = 16, desc = "RSA公钥{e,n}中的n")
    private byte[] n;
    @Schema(description = "n(BASE64编码)")
    private String nBase64;
    @Schema(description = "n(UTF8编码)")
    private String nUTF8;

    public T0A00_8A00() {
    }

    public T0A00_8A00(int e, byte[] n) {
        this.e = e;
        this.n = n;
    }

    public int getE() {
        return e;
    }

    public void setE(int e) {
        this.e = e;
    }

    public byte[] getN() {
        return n;
    }

    public void setN(byte[] n) {
        this.n = n;
    }

    public String getnBase64() {
        return nBase64;
    }

    public void setnBase64(String nBase64) {
        this.nBase64 = nBase64;
    }

    public String getnUTF8() {
        return nUTF8;
    }

    public void setnUTF8(String nUTF8) {
        this.nUTF8 = nUTF8;
    }

    public T0A00_8A00 build() {
        byte[] src = nUTF8.getBytes(StandardCharsets.UTF_8);
        if (src.length != 16)
            throw new APIException(APICodes.InvalidParameter, "n length is not 16");
        this.n = src;
        return this;
    }
}